﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using NUnit.Framework;

namespace Axial.Tests
{
	public class TestBase
	{
		protected string VerifyMethodOutput(string methodName, params string[] possibles)
		{
			string code = JSWebTranslator.DissembleMethod(GetType().GetMethod(methodName), new object[] { this }).ToString();
			code = code.Trim();
			Trace.WriteLine(methodName);
			Trace.WriteLine("------------------------------------");
			/*
			foreach (ILInstruction il in new MethodBodyReader(GetType().GetMethod(methodName)).Instructions)
				Trace.WriteLine(il);
			Trace.WriteLine("");
			foreach (ILInstruction il in ILOptimizer.Optimize(new MethodBodyReader(GetType().GetMethod(methodName)).Instructions))
				Trace.WriteLine(il);
			Trace.WriteLine("");
			*/
			Trace.WriteLine(code);
			Trace.WriteLine("");

			bool onematches = false;
			foreach (string possible in possibles)
				onematches |= code.TrimEnd().EndsWith(possible.Trim());
			Assert.IsTrue(onematches, "The generated code does not match any expected code.");

			return code;
		}
	}
}
